package com.source.jucutils;

import java.util.concurrent.TimeUnit;

/**
 * @Author wengqy
 * @Date 2021/1/20
 */
public class JoinDemo {

    public static void main(String[] args) {

        Thread  t1 = new Thread(()->{
            try {
                TimeUnit.MILLISECONDS.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            for (int i = 0; i < 4; i++) {
                System.out.println("T1  "+i);
            }
        });


        Thread  t2 = new Thread(()->{

            try {
                TimeUnit.MILLISECONDS.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            try {
                t1.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            for (int i = 0; i < 4; i++) {
                System.out.println("T2  "+i);
            }
        });

        Thread  t3 = new Thread(()->{

            try {
                TimeUnit.MILLISECONDS.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            try {
                t2.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            for (int i = 0; i < 4; i++) {
                System.out.println("T3  "+i);
            }
        });



        t1.start();
        t2.start();
        t3.start();
    }
}
